/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.LinkedList;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
 *
 * @author martin
 */
public class AFDtest {

    public AFDtest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of getQ method, of class Automata_Finito.
     */
    @Test
    public void Primera_Postest() {
        System.out.println("Primera_post");
        String cadena = "(a|b)(b|a*)";
        Arbol_Binario arbol = new Arbol_Binario();
        arbol.Generar_arbol(cadena);
        AFD afd = new AFD(arbol);
        //System.out.println("Ultima pos: "+afd.arbol.padre.getHijo_izquierdo().getNombre());
        //System.out.println("Ultima pos: "+afd.Primera_Pos(afd.arbol.padre.getHijo_derecho()).toString());

        //**********************************************************************
        String expResult = "[4, 5]";
        String result = afd.Primera_Pos(afd.arbol.padre.getHijo_izquierdo()).toString();
        assertEquals(expResult, result);
        //**********************************************************************
    }
    @Test
    public void Ultima_Postest() {
        System.out.println("Ultima_post");
        String cadena = "(a|b)(b|a*)";
        Arbol_Binario arbol = new Arbol_Binario();
        arbol.Generar_arbol(cadena);
        AFD afd = new AFD(arbol);
        //System.out.println("Ultima pos: "+afd.arbol.padre.getHijo_izquierdo().getNombre());
        //System.out.println("Ultima pos: "+afd.Primera_Pos(afd.arbol.padre.getHijo_derecho()).toString());

        //**********************************************************************
        String expResult = "[4, 5, 7, 9]";
        String result = afd.Ultima_Pos(afd.arbol.padre.getHijo_izquierdo()).toString();
        assertEquals(expResult, result);
        //**********************************************************************
    }
    //public LinkedList<Integer> Primera_Pos(Nodo<String> nodo)

    @Test
    public void Anulabletest() {

        System.out.println("Anulable");

        String cadena="(ab)*";
        Arbol_Binario arbol = new Arbol_Binario();
        arbol.Generar_arbol(cadena);
        AFD afd = new AFD(arbol);
        //**********************************************************************
        boolean expResult = true;
        boolean result = afd.Anulable(arbol.padre);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena="(a|b)|"+Main.epsilon;
        arbol.Generar_arbol(cadena);
        expResult = false;
        result = afd.Anulable(arbol.padre.getHijo_izquierdo());
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena="(a|b)|"+Main.epsilon;
        arbol.Generar_arbol(cadena);
        expResult = true;
        result = afd.Anulable(arbol.padre.getHijo_derecho());
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena="(ab)";
        arbol.Generar_arbol(cadena);
        expResult = false;
        result = afd.Anulable(arbol.padre.getHijo_izquierdo());
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena="(a)";
        arbol.Generar_arbol(cadena);
        expResult = false;
        result = afd.Anulable(arbol.padre);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena=Main.epsilon+""+Main.epsilon;
        arbol.Generar_arbol(cadena);
        expResult = true;
        result = afd.Anulable(arbol.padre);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena="(a|b)*|d";
        arbol.Generar_arbol(cadena);
        expResult = true;
        result = afd.Anulable(arbol.padre);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena="(a|b)*|d";
        arbol.Generar_arbol(cadena);
        expResult = true;
        result = afd.Anulable(arbol.padre);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena="ab|d";
        arbol.Generar_arbol(cadena);
        expResult = false;
        result = afd.Anulable(arbol.padre);
        assertEquals(expResult, result);
        //**********************************************************************
    }
    


}
